﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Mmht.DB
{
    public class NoticeDB
    {
        public DataTable GetAllNotice()
        {
            DataTable dt = new DataTable();
            string sql = string.Empty;
            sql = "select * from notice order by created_at desc";
            operate op = new operate();
            dt = op.Query(sql);
            return dt;
        }

        public DataTable GetLatestNotice(int number)
        {
            DataTable dt = new DataTable();
            string sql = string.Empty;
            sql = "select top " + number.ToString() + " id,name, emergency from notice order by created_at desc";
            operate op = new operate();
            dt = op.Query(sql);
            return dt;
        }

        public bool InsertNotice(string name, string notice, bool emergency, int created_by)
        {
            DateTime now = DateTime.Now;
            string sql = string.Empty;
            sql = "insert into notice(name,notice,emergency,created_at,created_by) values ( '"
                + name.ToString() + "','" + notice.ToString() + "','" + emergency + "','"
                + now + "','" + created_by.ToString() + "')";
            operate op = new operate();
            bool rst = op.Execute(sql);
            return rst;
        }
        public bool delNotice(int id) 
        {
            string sql = string.Empty;
            sql = "delete from notice where id="+id.ToString ()+"";
            operate op=new operate ();
            bool dl = op.Execute(sql);
            return dl;
        }
        public bool delAllNotice()
        {
            string sql = string.Empty;
            sql = "delete from notice";
            operate op = new operate();
            bool dl = op.Execute(sql);
            return dl;
        }
    }
}
